package function;

public class fun2 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,9};
        printArr(arr);
        int max = outPutMax(arr);
        System.out.println("最大值为："+max);
        boolean flag = isExist(13,arr);
        if(!flag) {
            System.out.println("不存在");
        }
        int [] newArray = copyArray(arr,4,8);
        printArr(newArray);
    }

    public static void printArr(int [] arr) {
        System.out.print('[');
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + (i== arr.length-1 ?"]":","));
        }
    }
    public static int outPutMax(int [] arr) {
        int temp = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(arr[i]>temp) {
                temp = arr[i];
            }
        }
         return temp;
    }

    public static boolean isExist(int num,int [] arr) {
        boolean flag = false;
        for (int j : arr) {
            if (j == num) {
                System.out.println("存在");
                flag = true;
                break;
            }
        }
        return flag;
    }

    public static int[] copyArray(int [] arr, int fromIndex,int toIndex) {
        int [] newArr = new int[toIndex-fromIndex];
        for (int i = fromIndex; i < toIndex; i++) {
            newArr[i-fromIndex] = arr[i+1];
        }
        return newArr;
    }

}


